package com.dgshanger.sanhxiaofeisc.mvp.presenter

import android.util.Log
import com.dgshanger.sanhxiaofeisc.entity.HomeEntity
import com.dgshanger.sanhxiaofeisc.mvp.contract.HomeContract
import com.dgshanger.sanhxiaofeisc.mvp.model.HomeModel
import com.xx.baseuilibrary.mvp.BaseMvpPresenter
import com.xx.baseutilslibrary.network.rx.XxBaseHttpObserver

/**
 * Created by JacobHHH on 2018/4/20.
 */
class HomePresenter : BaseMvpPresenter<HomeContract.Model, HomeContract.View>(), HomeContract.Presenter {

    override fun loadData(page: String?, longitude: String?, latitude: String?, isLoadMore: Boolean) {
            getModel().loadData(page,longitude,latitude,object : XxBaseHttpObserver<HomeEntity>(){
                override fun onCompleted(msg: String?, entity: HomeEntity?) {
                    getView()?.setData(entity,isLoadMore)
                }

                override fun onError(error: String?) {
                    Log.e("Tag","error="+error)
                    getView()?.showToast(error)
                    getView()?.onDataFailure(error)
                }

                override fun onStart() {

                }

                override fun onFinish() {

                }

            })
    }

    override fun createModel(): HomeContract.Model = HomeModel()
}